﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using CommunergyLogic;
using Communergy.Repository;
using Communergy.Common;
using Communergy.Repository.EntityFramework;

namespace CommunergyWebApplication.usercontrols
{
    public partial class UserMeterCombo : System.Web.UI.UserControl
    {
        private int _meterId;

        public int MeterId
        {
            get 
            {
                return Convert.ToInt32( cboMetersForUser.SelectedValue);
            }
            set 
            {
                cboMetersForUser.SelectedValue = value.ToString();
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            MembershipUser thisUser = Membership.GetUser();
            if (!Page.IsPostBack && thisUser != null)
            {
                var userGuid = new Guid(thisUser.ProviderUserKey.ToString());
                communergyEntities db = new communergyEntities(ConfigurationHelper.EntityFrameworkConnectionString);
                var userMeters = db.ElectricityMeter.Where(em => em.me_aspUserId == userGuid);
                cboMetersForUser.DataSource = userMeters;
                cboMetersForUser.DataBind();
            }
        }
    }

    
}